package com.example.source.spring.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Order(1)
public class AopAspect2 {

    public AopAspect2() {
    }

    @Pointcut("execution(* com.example.source.pojo.AdviserUser.*(..))")
    void pointcut() {
    }

    void test() {
        System.out.println("test");
    }

    @Before("pointcut()")
    void logBefore(JoinPoint joinPoint) {
        System.out.println(this + "@Before:" + joinPoint.getSignature().getName());
    }

    @After("pointcut()")
    void logAfter(JoinPoint joinPoint) {
        Object[] args = joinPoint.getArgs();
        System.out.println(this + "@After:" + joinPoint.getSignature().getName() + ";args:" + args);
    }

    @Around("pointcut()")
    Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        Object[] args = joinPoint.getArgs();
        System.out.println(this + "@Around前..." + joinPoint.getSignature().getName() + ";args:" + args);
        Object result = joinPoint.proceed();
        System.out.println(this + "@Around后..." + joinPoint.getSignature().getName() + ";args:" + args);
        return result;
    }

    @AfterReturning(value = "pointcut()", returning = "ret")
    void afterReturn(Object ret) {
        System.out.println(this + "@AfterReturning....");
    }

    @AfterThrowing(value = "pointcut()", throwing = "ex")
    void afterThrowing(Throwable ex) {
        System.out.println(this + "@AfterThrowing....");
    }
}
